// ActionScript file
 import flash.events.Event;
 import flash.net.FileFilter;
 import flash.net.FileReference;
 
 import mx.controls.Alert;
 private var fileRef:FileReference = new FileReference();
 private function init():void{
     
 }
 
 private function pickfile():void{
     var imageTypes:FileFilter = new FileFilter("图片 (*.jpg, *.jpeg, *.gif,*.png)", "*.jpg; *.jpeg; *.gif; *.png");
     var textTypes:FileFilter = new FileFilter("文本文件(*.txt","*.txt;");
     var officeType:FileFilter = new FileFilter("Office文件(*.doc, *.xls","*.doc; *.xls");
     var anyType:FileFilter = new FileFilter("所有文件(*.*)","*.*");
     var allTypes:Array = new Array(imageTypes, textTypes,officeType,anyType);
     fileRef.addEventListener(Event.SELECT, selectHandler);
     fileRef.addEventListener(Event.COMPLETE, completeHandler);
     fileRef.addEventListener(ProgressEvent.PROGRESS, progressHandler);
     fileRef.addEventListener("ioError", ioerrorHandler);
     try{
         var success:Boolean = fileRef.browse(allTypes);
     }catch (error:Error){
     	Alert.show(error.toString());
         trace("Unable to browse for files."+error.toString());
     }
 }
 private function ioerrorHandler(event:Event):void{
     trace("Unable to upload file."+event.toString());
 }
 private function progressHandler(event:ProgressEvent):void{
     lbProgress.text = " 已上传 " + (event.bytesLoaded/1024).toFixed(2)+ " K，共 " + (event.bytesTotal/1024).toFixed(2) + " K";
     var proc: uint = event.bytesLoaded / event.bytesTotal * 100;
     progress1.setProgress(proc, 100);
     progress1.label= "当前进度: " + " " + proc + "%";
 
 }
 private    function selectHandler(event:Event):void{
 	Alert.show(">>>>>>>>>>>>>");
     var request:URLRequest = new URLRequest("http://localhost:8080/performance/UploadExcelServlet")
     try
     {
         fileRef.upload(request);
     }
     catch (error:Error)
     {
     	Alert.show("CCCCCCCCCCC:"+error.getStackTrace());
         trace("Unable to upload file."+error.toString());
     }
 }
 private function completeHandler(event:Event):void{
   Alert.show("DONE");
     trace("uploaded");
 }// ActionScript file
